package com.sky.com.sky.web.app;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查询当前登陆人购物车列表
     * @return
     * **/
   @GetMapping("/list")
   public Result getList(){
       List<ShoppingCart> list = shoppingCartService.getList();
       return Result.success(list);
   }


    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     * **/
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.save(shoppingCartDTO);
        return Result.success();
    }


    /**
     * 清空购物车商品
     * @return
     * **/
    @DeleteMapping("/clean")
    public Result clean(){
        shoppingCartService.clean();
        return Result.success();
    }


    /**
     * 减购物车商品数量
     * @param shoppingCartDTO
     * @return
     * **/
   @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
       shoppingCartService.sub(shoppingCartDTO);
       return Result.success();
   }

}
